package com.example.administrator.himalaya.dialog;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;

import com.example.administrator.himalaya.R;

/**
 * Created by Administrator on 2016/12/9.
 */

public class CustomDialog extends AlertDialog.Builder implements View.OnClickListener {
    private Context context;
    private Button btn_1;
    private Button btn_2;
    private Button btn_3;
    private AlertDialog dialog;

    public CustomDialog(@NonNull Context context) {
        super(context);
        this.context = context;
        init();
    }

    private void init() {
        View rootView = LayoutInflater.from(context).inflate(R.layout.dialog_custom, null);
        btn_1 = ((Button) rootView.findViewById(R.id.btn_1));
        btn_2 = ((Button) rootView.findViewById(R.id.btn_2));
        btn_3 = ((Button) rootView.findViewById(R.id.btn_3));

        btn_1.setOnClickListener(this);
        btn_2.setOnClickListener(this);
        btn_3.setOnClickListener(this);
        setView(rootView);
    }

    public void showDialog() {
        dialog = create();
        dialog.show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_1:
                dialog.dismiss();
                break;
            case R.id.btn_2:
                break;
            case R.id.btn_3:
                //结束应用
                android.os.Process.killProcess(android.os.Process.myPid());
                break;
        }
        dialog.dismiss();
    }
}
